// myInternet Functionality Checker (MIFC)
// Advanced Internet Services
// 11/15/2011



public class ConnectionStatus {

	int numberOfAttempts;
	int numberPassed;
	
	public String latency;
	public boolean ipv6_status;
	public String uploadSpeed;
	public String downloadSpeed;
	
	enum lights {
		GREEN, YELLOW, RED, UNDEFINED
	}
	
	lights currentLightStatus;
	
	public ConnectionStatus () {
		numberOfAttempts = 0;
		numberPassed = 0;		
		currentLightStatus = lights.UNDEFINED;
		latency = "";
		ipv6_status = false;
		uploadSpeed = "";
		downloadSpeed = "";
	}
	
	public double percentPassed(){
	
			double percent = 0.0;
		
			if (this.numberOfAttempts != 0){
				percent = ((double)this.numberPassed)/((double)this.numberOfAttempts);
			} 
		return percent;
	}
	
	public void addFailedAttempt() {
		this.numberOfAttempts++;
		this.updateLights();
	}
	
	public void addPassedAttempt() {
		this.numberPassed++;
		this.numberOfAttempts++;
		this.updateLights();
	}
	
	private void updateLights(){
		if (this.numberOfAttempts == 0 && this.numberPassed == 0){
			this.currentLightStatus = lights.UNDEFINED;
		} else {
			if (this.percentPassed() <= 0.25) this.currentLightStatus = lights.RED;
			if (this.percentPassed() > 0.25 && this.percentPassed() < 0.95) this.currentLightStatus = lights.YELLOW;
			if (this.percentPassed() >= 0.95) this.currentLightStatus = lights.GREEN;
		}
	}
	
	public String getLightStatus() {
		return this.currentLightStatus.toString();
	}
	
	
} // end class
